package com.demo.lcgl.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.demo.lcgl.controller.base.BaseController;
import com.demo.lcgl.entity.FinancialPlanner;
import com.demo.lcgl.service.FinancialPlannerService;

/**
 * 理财规划师：(FinancialPlanner)表控制层
 */
@RestController
@RequestMapping("/financial_planner")
public class FinancialPlannerController extends BaseController<FinancialPlanner, FinancialPlannerService> {

    /**
     * 理财规划师对象
     */
    @Autowired
    public FinancialPlannerController(FinancialPlannerService service) {
        setService(service);
    }

    @PostMapping("/add")
    @Transactional
    public Map<String, Object> add(HttpServletRequest request) throws IOException {
        Map<String, Object> paramMap = service.readBody(request.getReader());
        Map<String, String> mapplanner_job_number = new HashMap<>();
        mapplanner_job_number.put("planner_job_number", String.valueOf(paramMap.get("planner_job_number")));
        List listplanner_job_number = service.selectBaseList(service.select(mapplanner_job_number, new HashMap<>()));
        if (listplanner_job_number.size() > 0) {
            return error(30000, "字段规划师工号内容不能重复");
        }
        this.addMap(paramMap);
        return success(1);
    }

}
